home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / java / appleevent send and receive / source / shared sources / errorhandler.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  1.7 KB  |  58 lines

  1. /**
  2.  * Apple Worldwide Developer Technical Support
  3.  *
  4.  * Sample showing how to send and receive AppleEvents using JDirect 2.
  5.  *
  6.  * File: ErrorHandler.java
  7.  *
  8.  * This class contains OSerr handling code.
  9.  * @see NativeException
  10.  *
  11.  * @author Levi Brown
  12.  * @author Apple Computer, Inc.
  13.  *
  14.  * Copyright ©1999 Apple Computer, Inc.
  15.  * All rights reserved.
  16.  *
  17.  * @version 1.0
  18.  * 4/15/1999 Shipped as 'AppleEvent Send and Receive' sample.
  19.  *
  20.  * You may incorporate this sample code into your applications without
  21.  * restriction, though the sample code has been provided "AS IS" and the
  22.  * responsibility for its operation is 100% yours.  However, what you are
  23.  * not permitted to do is to redistribute the source as "Apple Sample
  24.  * Code" after having made changes. If you're going to re-distribute the
  25.  * source, we require that you make it clear in the source that the code
  26.  * was descended from Apple Sample Code, but that you've made changes.
  27.  */
  28. public class ErrorHandler implements TypesConstants
  29. {
  30.     /**
  31.      * Checks to make sure no error has occured.
  32.      * If the err parameter does not equal noErr, an exception will
  33.      * be thrown containing a message.
  34.      * @param err the OSError retured by some toolbox call.
  35.      * @param errorText the message to use if an error has occured.
  36.      * @exception NativeException if err is not equal to noErr
  37.      * @see NativeException
  38.      */
  39.     public static void checkError(short err, String errorText) throws NativeException
  40.     {
  41.         if (err != noErr)
  42.         {
  43.             StringBuffer buffer = new StringBuffer();
  44.             if (errorText != null)
  45.             {
  46.                 buffer.append(errorText);
  47.                 buffer.append(": ");
  48.             }
  49.             else
  50.             {
  51.                 buffer.append("Error ");
  52.             }
  53.             buffer.append(err);
  54.             
  55.             throw new NativeException(buffer.toString(), err);
  56.         }
  57.     }
  58. }